[WPF] Custom TabItem in TabControl
Posted
by Simon
on Stack Overflow
See other posts from Stack Overflow
or by Simon
Published on 2010-04-17T21:53:32Z
Indexed on
2010/04/17
22:33 UTC
Read the original article
Hit count: 1491
I've created CustomTabItem which inherits from TabItem and i'd like to use it while binding ObservableCollection in TabControl
<TabControl ItemsSource="{Binding MyObservableCollection}"/>
It should like this in XAML, but i do not know how change default type of the output item created by TabControl while binding.
I've tried to create converter, but it has to do something like this inside convertin method:
List<CustomTabItem> resultList = new List<CustomTabItem>();
And iterate through my input ObservableCollection, create my CustomTab based on item from collection and add it to resultList...
I'd like to avoid it, bacause while creating CustomTabItem i'm creating complex View and it takes a while, so i don't want to create it always when something change in binded collection.
My class extends typical TabItem and i'd like to use this class in TabControl instead of TabItem.
<TabControl.ItemContainerStyle>
<Style TargetType="{x:Type local:CustomTabItem}">
<Setter Property="MyProperty" Value="{Binding xxx}"/>
</Style>
</TabControl.ItemContainerStyle>
Code above generates error that Style cannot be applied to TabItem.
My main purpose is to use in XAML my own CustomTabItem and bind properties... Just like above...
I've also tried to use
<TabControl.ItemTemplate/>
<TabControl.ContentTemaplte/>
But they are just styles for TabItem, so i'll still be missing my properties wchich i added in my custom class.
© Stack Overflow or respective owner